package com.spring.demo3;

import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public class MainApp {

	/**
	 * 依赖注入(构造函数)
	 */
	public void testDemo2(){
		AbstractApplicationContext context = new FileSystemXmlApplicationContext("src/test/resources/bean3.xml");
		TextEditor te = (TextEditor) context.getBean("textEditor");
		te.spellCheck();
	}
	/**
	 * 依赖注入(set方法)
	 */
	public void testDemo3(){
		AbstractApplicationContext context = new FileSystemXmlApplicationContext("src/test/resources/bean3.xml");
		TextEditor2 te = (TextEditor2) context.getBean("textEditor2");
		te.spellCheck();
	}
	/**
	 * 依赖注入(注入内部beans)
	 */
	public void testDemo4(){
		AbstractApplicationContext context = new FileSystemXmlApplicationContext("src/test/resources/bean3.xml");
		TextEditor2 te = (TextEditor2) context.getBean("textEditor3");
		te.spellCheck();
	}
	public static void main(String[] args) {
		System.out.println("构造器========================");
		new MainApp().testDemo2();
		System.out.println("setter========================");
		new MainApp().testDemo3();
		System.out.println("内部beans========================");
		new MainApp().testDemo4();
	}
}
